﻿/// <reference path="../common/list-base.js" />
!function () {
    var $ = fly;
    var pageHtml = ['<div id=top-empty></div><div id="title-block">',
                        '<input id=chk-noReceive type=radio name=chk-filter checked /><label for=chk-noReceive >未接收</label> ',
                        '<input id=chk-processing type=radio name=chk-filter /><label for=chk-processing >办理中</label> ',
                        '<input id=chk-completed type=radio name=chk-filter /><label for=chk-completed >已办结</label> ',
                        '<input id=chk-all type=radio name=chk-filter /><label for=chk-all >所有工作</label> ',
                    '</div>',
                    '<div id="list-container" class="nolink a-button">',
                    '</div>'].join('')
    $.box.InboxList = $.Class({
        name: "收件",
        title: '我的工作',
        base: $.base.ListBase,
        form: 'outbox-form',
        pageFormat: pageHtml,
        pageUrl: $.base.ajaxUrl('work', 'Inbox'),
        isFirstLoadData: true,
        setStateFilter: function () {
            var state = this.stateBoxs.filter(":checked")
            this.store.params.state = state[0].id.substr(4);
        },
        createMembers: function () {
            this.$base.createMembers.apply(this, arguments);
            this.stateBoxs = $("#title-block input");
            this.setStateFilter();
            this.stateBoxs.click(function () {
                this.setStateFilter();
                this.pager.go(0, true);
            }, this)

            this.store.onRequested(function (result) {
                if (this.isFirstLoadData && result.data.length == 0) {
                    setTimeout(function () {
                        $('#chk-processing').attr("checked", true).fire("click");
                    })
                }
                this.isFirstLoadData = false
            }, this)
        },
        createGrid: function () {
            var me = this;
            this.$base.createGrid.call(this, {
                columns: [{
                    dataIndex: 'flowNO',
                    header: '流水号',
                    renderer: function (flowNO, cell) {
                        if (cell.record.isBold)
                            cell.el.css("font-weight", "bold");
                        return flowNO
                    }
                }, {
                    dataIndex: "title",
                    header: "工作名称",
                    renderer: function (title, cell) {
                        if (cell.record.isBold)
                            cell.el.css("font-weight", "bold");
                        return title;
                    }
                }, {
                    dataIndex: "creator",
                    header: '发起人'
                }, {
                    dataIndex: "assignTime",
                    header: "时间",
                    renderer: function (v, cell) {
                        return v.format('yyyy-MM-dd HH:mm');
                    }
                }, {
                    header: "",
                    dataIndex: 'id',
                    renderer: function (id, cell) {
                        return '<a href="../common/form.htm?m=oa&form=inbox-process-form&id={0}">办理</a>'.format(id);
                    }
                }]
            });
        }
    });
    window.page = new $.box.InboxList()
    page.show();
} ()